﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Abp.Domain.Repositories;
using Abp.Domain.Services;
using Abp.UI;
using FwProject.Core.Restaurant;

namespace FwProject.Manager
{
    public class LoadCarManager: IDomainService
    {
        private readonly IRepository<LoadCar, Guid> _loadcarRepository;
        public LoadCarManager(IRepository<LoadCar, Guid> loadcarRepository)
        {
            _loadcarRepository = loadcarRepository;

        }
        /// <summary>
        /// 添加一个装车
        /// </summary>
        /// <param name="loadcar"></param>
        /// <returns></returns>
        public async Task<Guid> CreateLoadcar(LoadCar loadcar,long id)
        {

            var model = _loadcarRepository.GetAll().Where(o =>o.CarStatus!=CarStatus.配送完成 && o.DriverUserId==id).FirstOrDefault();
            if (model!=null)
                throw new UserFriendlyException(200,"当前汽车还未审核完结");

            return await _loadcarRepository.InsertAndGetIdAsync(loadcar);
        }
        /// <summary>
        ///修改装车信息
        /// </summary>
        /// <param name="loadcar"></param>
        /// <returns></returns>
        public async Task UpdateLoadcar(LoadCar loadcar)
        {

            await _loadcarRepository.UpdateAsync(loadcar);
        }
        /// <summary>
        ///  delete 一个装车
        /// </summary>
        /// <param name="loadcar"></param>
        /// <returns></returns>
        public async Task DeleteLoadcar(LoadCar loadcar)
        {

            await _loadcarRepository.DeleteAsync(loadcar);
        }
    }
}
